//
//  VIZCellToolBar.swift
//  VIZ微博
//
//  Created by 位立志 on 16/4/14.
//  Copyright © 2016年 位立志. All rights reserved.
//

import UIKit
import SnapKit

private let hig = 0.5

class VIZCellToolBar: UIView {

    //定义三个按钮
    var responseBtn : UIButton!
    var messageBtn: UIButton!
    var wellBtn : UIButton!
    //两个线
    var view1 : UIView = UIView()
    var view2 : UIView = UIView()
    
    //设置cellViewModel
    var cellViewModel : VIZCellViewModel?{
        didSet{
            responseBtn.setTitle(cellViewModel!.response, forState: .Normal)
            messageBtn.setTitle(cellViewModel?.message, forState: .Normal)
            wellBtn.setTitle(cellViewModel?.well, forState: .Normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUI() {
    
        view1.backgroundColor = UIColor.blackColor()
        
        self.addSubview(view1)
        
        view2.backgroundColor = UIColor.blackColor()
        
        self.addSubview(view2)
        

        
        
        
        responseBtn = self.addChildButton("转发", imageName: "timeline_icon_retweet")
        messageBtn = addChildButton("评论", imageName: "timeline_icon_comment")
        wellBtn = addChildButton("赞", imageName: "timeline_icon_like")
        
        responseBtn.snp_makeConstraints { (make) -> Void in
            
            make.left.top.bottom.equalTo(self)
        }
        view1.snp_makeConstraints { (make) -> Void in
            
            make.width.equalTo(1)
            make.height.equalTo(self.snp_height).multipliedBy(hig)
            make.left.equalTo(responseBtn.snp_right)
            make.centerY.equalTo(self)
            //make.right.equalTo(messageBtn.snp_left)
        }
        
        messageBtn.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(responseBtn)
            make.top.bottom.equalTo(self)
            make.left.equalTo(view1.snp_right)
        }
        view2.snp_makeConstraints { (make) -> Void in
            
            make.width.equalTo(1)
            make.height.equalTo(self.snp_height).multipliedBy(hig)
            make.left.equalTo(messageBtn.snp_right)
            //make.right.equalTo(wellBtn.snp_left)
            make.centerY.equalTo(self)
        }
        wellBtn.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(responseBtn)
            make.right.top.bottom.equalTo(self)
            make.left.equalTo(view2.snp_right)
        }

        
        
        
    
    }
    
    //传入参数 得到 按钮
    private func addChildButton(title: String, imageName: String) -> UIButton {
        let btn = UIButton()
        btn.titleLabel?.font = UIFont.systemFontOfSize(12)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        //设置背景图片
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        
        //自适应大小
        btn.sizeToFit()
        addSubview(btn)
        return btn
    }
    
    
    
    
    
    
    
}
